home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / BIGCANDL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.6 KB  |  127 lines

  1. {**********************************************}
  2. {   TBigCandleSeries (TCandleSeries)           }
  3. {   Copyright (c) 1996 by David Berneda        }
  4. {      Series Developer Kit Example            }
  5. {**********************************************}
  6. {$I teedefs.inc}
  7. unit BigCandl;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, Teengine, Series, OHLChart, CandleCh;
  14.  
  15. type
  16.   TBigCandleSeries = class(TCandleSeries)
  17.   private
  18.     { Private declarations }
  19.     FHorizGap,FVertGap:Longint;
  20.   protected
  21.     { Protected declarations }
  22.     Procedure DrawMark( ValueIndex:Longint; Const St:String;
  23.                         APosition:TSeriesMarkPosition); override;
  24.     Procedure SetHorizGap(Value:Longint);
  25.     Procedure SetVertGap(Value:Longint);
  26.   public
  27.     { Public declarations }
  28.     Constructor Create(AOwner: TComponent); override;
  29.   published
  30.     { Published declarations }
  31.     property HorizGap:Longint read FHorizGap write SetHorizGap;
  32.     property VertGap:Longint read FVertGap write SetVertGap;
  33.   end;
  34.  
  35. implementation
  36.  
  37. Uses Chart,TeCanvas,
  38.      TeeProco;  { <-- needed only for the "Samples" constant }
  39.  
  40. Constructor TBigCandleSeries.Create(AOwner: TComponent);
  41. begin
  42.   inherited Create(AOwner);
  43.   FHorizGap:=20;
  44.   FVertGap:=6;
  45.   Marks.Visible:=True;
  46. end;
  47.  
  48. Procedure TBigCandleSeries.SetHorizGap(Value:Longint);
  49. begin
  50.   SetLongintProperty(FHorizGap,Value);
  51. end;
  52.  
  53. Procedure TBigCandleSeries.SetVertGap(Value:Longint);
  54. begin
  55.   SetLongintProperty(FVertGap,Value);
  56. end;
  57.  
  58. Procedure TBigCandleSeries.DrawMark( ValueIndex:Longint; Const St:String;
  59.                                      APosition:TSeriesMarkPosition);
  60. Var tmp           : String;
  61.     tmpX          : Integer;
  62.     tmpHorizOffset: Longint;
  63.     tmpVertOffset : Longint;
  64.     tmpOpen       : Longint;
  65.     tmpHigh       : Longint;
  66.     tmpLow        : Longint;
  67.     tmpClose      : Longint;
  68. begin
  69.   { the four prices screen Y coordinates }
  70.   { remember:  Y coordinates are inverted }
  71.   tmpOpen :=CalcYPosValue(OpenValues.Value[ValueIndex]);
  72.   tmpClose:=CalcYPosValue(CloseValues.Value[ValueIndex]);
  73.   tmpHigh :=CalcYPosValue(HighValues.Value[ValueIndex]);
  74.   tmpLow  :=CalcYPosValue(LowValues.Value[ValueIndex]);
  75.  
  76.   With APosition do
  77.   begin
  78.     tmpHorizOffset:=(Width div 2)+ FHorizGap ;  { <-- custom horiz "gap" }
  79.     tmpVertOffset :=Height + FVertGap;       { <-- custom vert "gap" }
  80.  
  81.     tmpX:=LeftTop.X;
  82.  
  83.     { Open Price Mark }
  84.     With LeftTop do
  85.     begin
  86.       Y:=tmpOpen-(Height div 2);
  87.       X:=tmpX-tmpHorizOffset;
  88.     end;
  89.     tmp:=FormatFloat(ValueFormat,OpenValues.Value[ValueIndex]);
  90.     inherited DrawMark(ValueIndex,tmp,APosition);
  91.  
  92.     { Close Price Mark }
  93.     With LeftTop do
  94.     begin
  95.       Y:=tmpClose-(Height div 2);
  96.       X:=tmpX+tmpHorizOffset;
  97.     end;
  98.     tmp:=FormatFloat(ValueFormat,CloseValues.Value[ValueIndex]);
  99.     inherited DrawMark(ValueIndex,tmp,APosition);
  100.  
  101.     { High Price Mark }
  102.     LeftTop.Y:=tmpHigh-tmpVertOffset;
  103.     tmp:=FormatFloat(ValueFormat,HighValues.Value[ValueIndex]);
  104.     inherited DrawMark(ValueIndex,tmp,APosition);
  105.  
  106.     { Low Price Mark }
  107.     LeftTop.Y:=tmpLow+tmpVertOffset-Height;
  108.     tmp:=FormatFloat(ValueFormat,LowValues.Value[ValueIndex]);
  109.     inherited DrawMark(ValueIndex,tmp,APosition);
  110.   end;
  111. end;
  112.  
  113. Procedure TeeBigCandleExitProc; far;
  114. begin
  115.   UnRegisterTeeSeries([TBigCandleSeries]);
  116. end;
  117.  
  118. initialization
  119.   RegisterTeeSeries( TBigCandleSeries, 'Big Candle', TeeMsg_GallerySamples, 1 );
  120. {$IFDEF D1}
  121.   AddExitProc(TeeBigCandleExitProc);
  122. {$ELSE}
  123. finalization
  124.   TeeBigCandleExitProc;
  125. {$ENDIF}
  126. end.
  127.